using UnityEngine;
using System.Collections;
using UnityEngine.UI.Windows;
using UnityEngine.UI;
using UnityEngine.Events;
using System;
using UnityEngine.UI.Windows.Components.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI.Windows.Extensions;
using UnityEngine.UI.Windows.Components.Modules;

namespace UnityEngine.UI.Windows.Components {

	public enum ColorState : byte {

		Normal,
		Highlighted,
		Pressed,
		Disabled,

	};

	public static class ButtonComponentUtils {
		
		public static bool IsInteractableAndActive(this IComponent item) {

			if (item == null) return false;

			IInteractableComponent button = null;
			if (item is LinkerComponent) {

				button = (item as LinkerComponent).Get<IInteractableComponent>();

			} else {

				button = item as IInteractableComponent;

			}

			if (button != null && button.IsVisible() == true && button.IsInteractable() == true) return true;

			return false;

		}

	};

	public class ButtonComponent : WindowComponentNavigation, IButtonComponent, IEventSystemHandler {
		
		public override void Setup(IComponentParameters parameters) {
			
			base.Setup(parameters);
			
			var inputParameters = parameters as ButtonComponentParameters;
			{
				if (inputParameters != null) inputParameters.Setup(this as IButtonComponent);
			}

			#region macros UI.Windows.Initialization.TextComponent 
	/*
	 * This code is auto-generated by Macros Module
	 * Do not change anything
	 */
	{
					
					if (inputParameters != null) inputParameters.Setup(this as ITextComponent);
	
				}
	#endregion

			#region macros UI.Windows.Initialization.ImageComponent 
	/*
	 * This code is auto-generated by Macros Module
	 * Do not change anything
	 */
	{
					if (inputParameters != null) inputParameters.Setup(this as IImageComponent);
	
				}
	#endregion

		}

		public override void OnWindowInactive() {

			base.OnWindowInactive();

			#region macros UI.Windows.OnWindowInactive.TextComponent
			#endregion

			#region macros UI.Windows.OnWindowInactive.ImageComponent 
	/*
	 * This code is auto-generated by Macros Module
	 * Do not change anything
	 */
	{
					
					this.tempMovieIsPlaying = this.IsPlaying();
					this.Pause();
	
				}
	#endregion

		}

		public override void OnWindowActive() {

			base.OnWindowActive();

			#region macros UI.Windows.OnWindowActive.TextComponent
			#endregion

			#region macros UI.Windows.OnWindowActive.ImageComponent 
	/*
	 * This code is auto-generated by Macros Module
	 * Do not change anything
	 */
	{
					
					if (this.tempMovieIsPlaying == true) {
	
						this.Play();
						this.tempMovieIsPlaying = false;
	
					}
	
				}
	#endregion

		}

		public override void OnLocalizationChanged() {

			base.OnLocalizationChanged();

			#region macros UI.Windows.OnLocalizationChanged.TextComponent 
	/*
	 * This code is auto-generated by Macros Module
	 * Do not change anything
	 */
	{
	
					if (this.lastTextLocalization == true) {
	
						this.SetText(this.lastTextLocalizationKey, this.lastTextLocalizationParameters);
	
					} else {
	
						if (this.text is UnityEngine.UI.Windows.Plugins.Localization.UI.LocalizationText) {
	
							(this.text as UnityEngine.UI.Windows.Plugins.Localization.UI.LocalizationText).OnLocalizationChanged();
	
						}
	
					}
	
				}
	#endregion

			#region macros UI.Windows.OnLocalizationChanged.ImageComponent 
	/*
	 * This code is auto-generated by Macros Module
	 * Do not change anything
	 */
	{
					
					if (this.lastImageLocalization == true) {
	
						this.SetImage(this.lastImageLocalizationKey, this.lastImageLocalizationParameters);
	
					} else {
	
						if (this.image is UnityEngine.UI.Windows.Plugins.Localization.UI.LocalizationImage) {
	
							(this.image as UnityEngine.UI.Windows.Plugins.Localization.UI.LocalizationImage).OnLocalizationChanged();
	
						}
	
					}
	
				}
	#endregion

		}

		public override void OnInit() {

			base.OnInit();

			if (this.button != null) {

				this.button.onClick.AddListener(this.OnClick);
				if (this.button is ButtonExtended) {

					(this.button as ButtonExtended).Setup(this);

				}

			}

			if (this.setDefaultNavigationModeOnStart == true) {

				this.SetNavigationMode(this.defaultNavigationMode);

			}

			#region macros UI.Windows.OnInit.TextComponent 
	/*
	 * This code is auto-generated by Macros Module
	 * Do not change anything
	 */
	{
	
					this.textCrossFadeModule.Init(this);
	
					if (this.textLocalizationKey.IsNone() == false) {
	
						this.SetText(this.textLocalizationKey);
	
					}
	
				}
	#endregion
			
			#region macros UI.Windows.OnInit.ImageComponent 
	/*
	 * This code is auto-generated by Macros Module
	 * Do not change anything
	 */
	{
	
					this.tempImagePlayOnShow = false;
	
					if (this.imageLocalizationKey.IsNone() == false) {
	
						if ((this.imageResource.controlType & ResourceAuto.ControlType.Init) != 0) {
	
							this.SetImage(this.imageLocalizationKey);
	
						}
	
					} else {
						
						WindowSystemResources.LoadAuto(this, onDataLoaded: () => {
	
							this.tempImagePlayOnShow = true;
	
							if (this.IsVisible() == true) {
	
								if (this.playOnShow == true) {
	
									this.Play();
	
								}
	
							}
	
						}, onComplete: null, onShowHide: false);
	
					}
	
					this.imageCrossFadeModule.Init(this);
	
				}
	#endregion

		}

		#region WindowComponent events
		public override void OnDeinit(System.Action callback) {
			
			base.OnDeinit(callback);
			
			#region macros UI.Windows.OnDeinit.TextComponent
			#endregion
			
			#region macros UI.Windows.OnDeinit.ImageComponent 
	/*
	 * This code is auto-generated by Macros Module
	 * Do not change anything
	 */
	{
	
					this.Stop();
					
					WindowSystemResources.UnloadAuto(this, onShowHide: false);
	
				}
	#endregion

			//this.onState = null;
			//this.onStateActive = false;
			
			if (this.button != null) {

				this.button.onClick.RemoveListener(this.OnClick);

			}

			this.callback.RemoveAllListeners();
			this.callbackButton.RemoveAllListeners();

		}

		public override void DoShowBegin(AppearanceParameters parameters) {
			
			#region macros UI.Windows.DoShowBegin.TextComponent
			#endregion

			#region macros UI.Windows.DoShowBegin.ImageComponent 
	/*
	 * This code is auto-generated by Macros Module
	 * Do not change anything
	 */
	{
					
					if (this.imageResourceWait == true && this.imageResource.IsLoadable() == true) {
						
						WindowSystemResources.LoadAuto(this, onDataLoaded: () => {
	
							this.tempImagePlayOnShow = true;
	
							if (this.playOnShow == true) {
	
								this.Play();
	
							}
	
						}, onComplete: () => {
	
							base.DoShowBegin(parameters);
	
						}, onShowHide: true,
							onFailed: () => {
	
								base.DoShowBegin(parameters);
	
							});
	
					} else {
	
						base.DoShowBegin(parameters);
	
					}
	
				}
	#endregion

		}

		public override void OnShowBegin() {
			
			base.OnShowBegin();
			
			//this.onStateActive = true;

			if (this.selectByDefault == true) {

				this.Select();

			}
			
			#region macros UI.Windows.OnShowBegin.TextComponent
			#endregion

			#region macros UI.Windows.OnShowBegin.ImageComponent 
	/*
	 * This code is auto-generated by Macros Module
	 * Do not change anything
	 */
	{
	
					if (this.imageCrossFadeModule.IsValid() == true) {
	
						this.imageCrossFadeModule.Prepare(this);
	
					}
	
					if (this.imageLocalizationKey.IsNone() == false) {
	
						if ((this.imageResource.controlType & ResourceAuto.ControlType.Show) != 0) {
	
							this.SetImage(this.imageLocalizationKey);
	
						}
	
					} else {
						
						WindowSystemResources.LoadAuto(this, onDataLoaded: () => {
	
							if (this.playOnShow == true) {
	
								this.Play();
	
							}
	
						}, onComplete: null, onShowHide: true);
	
					}
	
					if (this.tempImagePlayOnShow == true) {
	
						if (this.playOnShow == true) {
	
							this.Play();
	
						}
	
					}
	
				}
	#endregion

		}
		
		public override void OnHideEnd() {
			
			base.OnHideEnd();
			
			#region macros UI.Windows.OnHideEnd.TextComponent
			#endregion
			
			#region macros UI.Windows.OnHideEnd.ImageComponent 
	/*
	 * This code is auto-generated by Macros Module
	 * Do not change anything
	 */
	{
					
					//this.Stop();
	
					WindowSystemResources.UnloadAuto(this, onShowHide: true);
	
				}
	#endregion

			//this.onStateActive = false;
			
		}

		public override void OnHideBegin() {
			
			base.OnHideBegin();

			#region macros UI.Windows.OnHideBegin.TextComponent
			#endregion

			#region macros UI.Windows.OnHideBegin.ImageComponent
			#endregion

			this.OnPointerExit(null);
			
		}
		#endregion

		#region Button Base
		[Header("Button Component")]
		private ComponentEvent callback = new ComponentEvent();
		private ComponentEvent<ButtonComponent> callbackButton = new ComponentEvent<ButtonComponent>();

		[SerializeField]
		[BeginGroup("button")]
		protected Button button;
		[SerializeField]
		private bool setDefaultNavigationModeOnStart = true;
		[SerializeField][ReadOnly("setDefaultNavigationModeOnStart", state: false)]
		private Navigation.Mode defaultNavigationMode = Navigation.Mode.None;
		[SerializeField][EndGroup]
		protected bool selectByDefault;

		public virtual IButtonComponent SetSelectByDefault(bool state) {
			
			this.selectByDefault = state;
			
			return this;
			
		}

		public IButtonComponent SetNavigationMode(Navigation.Mode mode) {

			if (this.button != null) {

				var nav = this.button.navigation;
				nav.mode = mode;
				this.button.navigation = nav;

			}

			return this;

		}
		
		public void SetLabelStateColor(ColorState state, Color color) {
			
			if (this.button.IsDestroyed() == true) return;

			var button = this.button as ButtonWithLabel;
			if (button == null) return;

			var colors = button.labelColor;
			if (state == ColorState.Normal) colors.normalColor = color;
			if (state == ColorState.Highlighted) colors.highlightedColor = color;
			if (state == ColorState.Pressed) colors.pressedColor = color;
			if (state == ColorState.Disabled) colors.disabledColor = color;
			button.labelColor = colors;
			
			this.Refresh();

		}
		
		public Color GetLabelStateColor(ColorState state) {
			
			var button = this.button as ButtonWithLabel;
			if (button == null) return default(Color);
			
			var colors = button.labelColor;
			if (state == ColorState.Normal) return colors.normalColor;
			if (state == ColorState.Highlighted) return colors.highlightedColor;
			if (state == ColorState.Pressed) return colors.pressedColor;
			if (state == ColorState.Disabled) return colors.disabledColor;
			
			return default(Color);
			
		}

		public void SetStateColor(ColorState state, Color color) {
			
			if (this.button.IsDestroyed() == true) return;

			var colors = this.button.colors;
			if (state == ColorState.Normal) colors.normalColor = color;
			if (state == ColorState.Highlighted) colors.highlightedColor = color;
			if (state == ColorState.Pressed) colors.pressedColor = color;
			if (state == ColorState.Disabled) colors.disabledColor = color;
			this.button.colors = colors;

			this.Refresh();

		}
		
		public Color GetStateColor(ColorState state) {
			
			var colors = this.button.colors;
			if (state == ColorState.Normal) return colors.normalColor;
			if (state == ColorState.Highlighted) return colors.highlightedColor;
			if (state == ColorState.Pressed) return colors.pressedColor;
			if (state == ColorState.Disabled) return colors.disabledColor;

			return default(Color);

		}

		public void Refresh() {
			
			if (this.button.IsDestroyed() == true) return;

			ColorBlock colors;
			var labelFadeDuration = 0f;
			var buttonLabel = this.button as ButtonWithLabel;
			if (buttonLabel != null) {

				colors = buttonLabel.labelColor;
				labelFadeDuration = colors.fadeDuration;
				colors.fadeDuration = 0f;
				buttonLabel.labelColor = colors;

			}

			colors = this.button.colors;
			var fadeDuration = colors.fadeDuration;
			colors.fadeDuration = 0f;
			this.button.colors = colors;

			this.button.interactable = !this.button.interactable;
			this.button.interactable = !this.button.interactable;
			
			colors = this.button.colors;
			colors.fadeDuration = fadeDuration;
			this.button.colors = colors;

			if (buttonLabel != null) {

				colors = buttonLabel.labelColor;
				colors.fadeDuration = labelFadeDuration;
				buttonLabel.labelColor = colors;

			}

		}

		public virtual Selectable GetSelectable() {

			return this.button;
			
		}

		#region source macros UI.Windows.ButtonComponent.States

		[SerializeField][ReadOnly("hoverIsActive", state: false)]
		private bool hoverOnAnyButtonState = false;
		[SerializeField][ReadOnly("hoverIsActive", state: false)]
		private bool hoverCursorDefaultOnInactive = false;

		public bool IsHoverCursorDefaultOnInactive() {

			return this.IsInteractable() == false && this.hoverCursorDefaultOnInactive == true;

		}

		public void Select() {

			this.GetSelectable().Select();

		}

		public virtual IInteractableComponent SetEnabledState(bool state) {

			if (state == true) {

				this.SetEnabled();

			} else {

				this.SetDisabled();

			}

			return this;

		}

		public virtual IInteractableComponent SetDisabled() {

			var sel = this.GetSelectable();
			if (sel != null) {

				if (sel.interactable != false) {

					sel.interactable = false;
					this.OnInteractableChanged();

				}

			}

			return this;

		}

		public virtual IInteractableComponent SetEnabled() {

			var sel = this.GetSelectable();
			if (sel != null) {

				if (sel.interactable != true) {

					sel.interactable = true;
					this.OnInteractableChanged();

				}

			}

			return this;

		}

		public IInteractableComponent SetHoverOnAnyButtonState(bool state) {

			this.hoverOnAnyButtonState = state;

			return this;

		}

		protected override bool ValidateHoverPointer() {

			if (this.hoverOnAnyButtonState == false && this.IsInteractable() == false) return false;
			return base.ValidateHoverPointer();

		}

		public bool IsInteractable() {

			var sel = this.GetSelectable();
			return (sel != null ? sel.IsInteractable() : false);

		}

		public virtual void OnInteractableChanged() {

		}
		#endregion

		public bool IsInteractableAndHasEvents() {

			return this.IsInteractable() == true /*&&
				(
					this.callback.GetPersistentEventCount() > 0 ||
					this.callbackButton.GetPersistentEventCount() > 0 ||
					this.button.onClick.GetPersistentEventCount() > 0
				)*/;

		}

		/*
		public IButtonComponent SetEnabledState(System.Func<bool> onState) {

			this.onState = onState;
			this.oldState = this.onState();
			this.onStateActive = true;

			return this;

		}

		public virtual void LateUpdate() {

			if (this.onStateActive == true && this.onState != null) {

				var newState = this.onState();
				if (newState != this.oldState) this.SetEnabledState(newState);
				this.oldState = newState;

			}

		}*/

		public virtual IButtonComponent SetButtonColor(Color color) {

			if (this.button != null && this.button.targetGraphic != null) {

				this.button.targetGraphic.color = color;

			}

			return this;

		}
		
		public virtual IButtonComponent RemoveAllCallbacks() {

			if (this.button == null) return this;

			this.callback.RemoveAllListeners();
			this.callbackButton.RemoveAllListeners();

			return this;
			
		}

		public virtual IButtonComponent RemoveCallback(System.Action callback) {

			if (this.button == null) return this;

			this.callback.RemoveListener(callback);

			return this;
			
		}
		
		public virtual IButtonComponent RemoveCallback(System.Action<ButtonComponent> callback) {

			if (this.button == null) return this;

			this.callbackButton.RemoveListener(callback);

			return this;
			
		}

		public virtual IButtonComponent SetCallback(System.Action callback) {

			if (this.button == null) return this;

            this.callback.RemoveAllListeners();
            this.callback.AddListenerDistinct(callback);
			this.callbackButton.RemoveAllListeners();

			return this;

		}
		
		public virtual IButtonComponent SetCallback(System.Action<ButtonComponent> callback) {

			if (this.button == null) return this;

			this.callbackButton.RemoveAllListeners();
			this.callbackButton.AddListenerDistinct(callback);
			this.callback.RemoveAllListeners();

			return this;
			
		}

		public virtual IButtonComponent AddCallback(System.Action callback) {

			if (this.button == null) return this;

			this.callback.AddListenerDistinct(callback);

			return this;

		}

		public virtual IButtonComponent AddCallback(System.Action<ButtonComponent> callback) {

			if (this.button == null) return this;

			this.callbackButton.AddListenerDistinct(callback);

			return this;

		}

		public IInteractableControllerComponent Click() {

			var sel = this.GetSelectable();
			if (sel != null) {

				var pointer = new PointerEventData(EventSystem.current);
				ExecuteEvents.Execute(sel.gameObject, pointer, ExecuteEvents.submitHandler);

			}

			return this;

		}

		public virtual void OnClick() {

			if (this.GetWindow() != null &&
				this.GetWindow().GetState() != WindowObjectState.Shown &&
			    this.GetWindow().GetState() != WindowObjectState.Showing &&
				this.GetWindow().GetActiveState() != ActiveState.Active) {

				#if UNITY_EDITOR || DEBUGBUILD
				if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true) UnityEngine.Debug.LogWarningFormat("Can't send click on `{0}` state. Be sure `{1}` window has the `Shown` or `Showing` state and is active.", this.GetWindow().GetState(), this.GetWindow().name);
				#endif
				return;

			}

			if (WindowSystemInput.CanClickOnElement(this) == false) return;

			this.sfxOnClick.Play();

			if (this.callback != null) this.callback.Invoke();
			if (this.callbackButton != null) this.callbackButton.Invoke(this);

			WindowSystemInput.RaiseWaitForClickOnElement(this);

		}
		#endregion

		#region macros UI.Windows.ImageComponent (overrideColor:override)

	/*
	 * This code is auto-generated by Macros Module
	 * Do not change anything
	 */
	[Header("Image Component")]
			[SerializeField]
			private Image image;
			[BeginGroup("image")][SerializeField]
			private RawImage rawImage;
	
			[SerializeField]
			private bool flipHorizontal;
			[SerializeField]
			private bool flipVertical;
	
			private bool flipHorizontalInternal;
			private bool flipVerticalInternal;
	
			[SerializeField]
			private bool preserveAspect;
	
			[HideInInspector][SerializeField]
			private UIFlippable flippableEffect;
			[HideInInspector][SerializeField]
			private UIPreserveAspect preserveAspectEffect;
	
			public UnityEngine.UI.Windows.Plugins.Localization.LocalizationKey imageLocalizationKey;
	
			[ReadOnly("rawImage", null)]
			[SerializeField][UnityEngine.Serialization.FormerlySerializedAs("playOnStart")]
			private bool playOnShow;
			[ReadOnly("rawImage", null)]
			[SerializeField]
			private bool loop;
	
			[SerializeField]
			private bool imageResourceWait = false;
			[SerializeField]
			private ResourceAuto imageResource = new ResourceAuto();
	
			[EndGroup][SerializeField]
			private ImageCrossFadeModule imageCrossFadeModule = new ImageCrossFadeModule();
	
			private bool tempImagePlayOnShow = false;
			private bool tempMovieIsPlaying = false;
	
			public ResourceBase GetResource() {
	
				return this.imageResource;
	
			}
	
			public IImageComponent SetPreserveAspectState(bool state) {
	
				this.preserveAspect = state;
	
				return this;
	
			}
	
			public IImageComponent SetLoop(bool state) {
	
				this.loop = state;
	
				return this;
	
			}
	
			public bool IsLoop() {
				
				return this.loop;
	
			}
			
			public bool IsMovie() {
				
				var image = this.GetRawImageSource();
				if (image == null) return false;
				
				return MovieSystem.IsMovie(image.mainTexture);
				
			}
	
			public IImageComponent Unload(ResourceBase resource) {
	
				WindowSystemResources.Unload(this, resource);
	
				return this;
	
			}
	
			public void SetVerticesDirty() {
	
				if (this.image != null) this.image.SetVerticesDirty();
				if (this.rawImage != null) this.rawImage.SetVerticesDirty();
	
			}
	
			public IImageComponent SetImageLocalizationKey(UnityEngine.UI.Windows.Plugins.Localization.LocalizationKey key) {
	
				this.imageLocalizationKey = key;
	
				return this;
	
			}
	
			public IImageComponent SetMovieTexture(ResourceAuto resource, System.Action onDataLoaded, System.Action onComplete = null, System.Action onFailed = null) {
	
				this.flipVerticalInternal = MovieSystem.IsVerticalFlipped();
				this.SetVerticesDirty();
	
				this.Stop();
				this.SetImage(resource,
					onDataLoaded: () => {
						
						if (onDataLoaded != null) onDataLoaded.Invoke();
	
					},
					onComplete: () => {
	
						//if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true) UnityEngine.Debug.Log("SetMovieTexture: " + this.name);
						MovieSystem.UnregisterOnUpdateTexture(this.ValidateTexture);
						MovieSystem.RegisterOnUpdateTexture(this.ValidateTexture);
						if (onComplete != null) onComplete.Invoke();
	
					},
					onFailed: onFailed);
	
				return this;
				
			}
	
			private void ValidateTexture(IImageComponent component, Texture texture) {
	
				//if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true) UnityEngine.Debug.Log("ValidateTexture: " + (component as MonoBehaviour) + ", tex: " + texture, component as MonoBehaviour);
				if (this as IImageComponent == component) {
					
					if (this.rawImage != null) {
	
						if (this.imageCrossFadeModule.IsValid() == true) {
	
							this.imageCrossFadeModule.ValidateTexture(texture);
	
						} else {
	
							this.rawImage.texture = texture;
	
						}
	
					}
	
				}
	
			}
	
			public bool GetPlayOnShow() {
				
				return this.playOnShow;
				
			}
			
			public IImageComponent SetPlayOnShow(bool state) {
				
				this.playOnShow = state;
				
				return this;
	
			}
			
			public virtual bool IsPlaying() {
	
				return MovieSystem.IsPlaying(this);
	
			}
			
			public virtual IImageComponent PlayAndPause() {
	
				MovieSystem.PlayAndPause(this, this.loop);
	
				return this;
				
			}
	
			public virtual IImageComponent Rewind(bool pause = true) {
	
				MovieSystem.Rewind(this, pause);
	
				return this;
	
			}
	
			public virtual IImageComponent Play() {
	
				return this.Play(this.loop);
	
			}
	
			public virtual IImageComponent Play(bool loop) {
	
				MovieSystem.Play(this, loop);
	
				return this;
	
			}
	
			public virtual IImageComponent Play(bool loop, System.Action onComplete) {
	
				MovieSystem.Play(this, loop, onComplete);
	
				return this;
	
			}
	
			public virtual IImageComponent Stop() {
	
				MovieSystem.UnregisterOnUpdateMaterial(this.ValidateMaterial);
				MovieSystem.UnregisterOnUpdateTexture(this.ValidateTexture);
				MovieSystem.Stop(this);
	
				return this;
	
			}
	
			public virtual IImageComponent Pause() {
	
				MovieSystem.Pause(this);
	
				return this;
	
			}
	
			public Texture GetTexture() {
	
				if (this.image != null) {
	
					return (this.image.sprite != null ? this.image.sprite.texture : null);
	
				}
	
				if (this.rawImage != null) {
	
					return this.rawImage.texture;
	
				}
	
				return null;
	
			}
	
			public IImageComponent ResetImage() {
				
				if (this.image != null) {
					
					this.image.sprite = null;
					
				}
				
				if (this.rawImage != null) {
	
					this.Stop();
					this.rawImage.texture = null;
					
				}
	
				this.flipHorizontalInternal = false;
				this.flipVerticalInternal = false;
	
				return this;
	
			}
	
			Graphic IImageComponent.GetGraphicSource() {
	
				if (this.image != null) return this.image;
				return this.rawImage;
	
			}
	
			public Image GetImageSource() {
				
				return this.image;
				
			}
			
			public RawImage GetRawImageSource() {
				
				return this.rawImage;
				
			}
	
			public bool IsHorizontalFlip() {
	
				return this.flipHorizontal == true || this.flipHorizontalInternal == true;
	
			}
	
			public bool IsVerticalFlip() {
	
				return this.flipVertical == true || this.flipVerticalInternal == true;
	
			}
	
			public bool IsPreserveAspect() {
	
				return this.preserveAspect;
	
			}
	
			public IImageComponent SetImage(ImageComponent source) {
				
				if (source.GetImageSource() != null) this.SetImage(source.GetImageSource().sprite);
				if (source.GetRawImageSource() != null) this.SetImage(source.GetRawImageSource().texture);
				
				return this;
				
			}
	
			public IImageComponent SetImage(ResourceAuto resource, System.Action onDataLoaded = null, System.Action onComplete = null, System.Action onFailed = null) {
	
				ME.Coroutines.Run(this.SetImage_INTERNAL(resource, onDataLoaded, onComplete, onFailed));
	
				return this;
				
			}
	
			private System.Collections.Generic.IEnumerator<byte> SetImage_INTERNAL(ResourceAuto resource, System.Action onDataLoaded = null, System.Action onComplete = null, System.Action onFailed = null) {
	
				yield return 0;
	
				if (this.imageCrossFadeModule.IsValid() == true) {
	
					this.imageCrossFadeModule.Prepare(this);
	
				}
	
				var oldResource = this.imageResource;
				var newResource = resource;
				this.imageResource = resource;
	
				// if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true) UnityEngine.Debug.Log("Loading resource: " + this.imageResource.GetId());
				WindowSystemResources.Load(this,
					onDataLoaded: onDataLoaded,
					onComplete: () => {
	
						//if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true) UnityEngine.Debug.Log("Resource loaded: " + newResource.GetId() + " :: " + this.name, this);
						if (newResource.GetId() != oldResource.GetId()) {
	
							// if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true) UnityEngine.Debug.Log("Unloading: " + newResource.GetId() + " != " + oldResource.GetId() + " :: " + this.name, this);
							WindowSystemResources.Unload(this, oldResource, resetController: false);
	
						}
	
	
						if (onComplete != null) onComplete.Invoke();
	
					},
					onFailed: () => {
	
						//if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true) UnityEngine.Debug.Log("Resource loading failed: " + newResource.GetId() + " :: " + this.name, this);
						if (newResource.GetId() != oldResource.GetId()) {
	
							//if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true) UnityEngine.Debug.Log("Failed, Unloading: " + this.imageResource.GetId() + " != " + oldResource.GetId() + " :: " + this.name, this);
							WindowSystemResources.Unload(this, oldResource, resetController: false);
	
						}
	
						if (onFailed != null) onFailed.Invoke();
	
					}
				);
	
			}
	
			private bool lastImageLocalization = false;
			private Plugins.Localization.LocalizationKey lastImageLocalizationKey;
			private object[] lastImageLocalizationParameters;
			public IImageComponent SetImage(UnityEngine.UI.Windows.Plugins.Localization.LocalizationKey key, params object[] parameters) {
	
				if (this.imageCrossFadeModule.IsValid() == true) {
	
					this.imageCrossFadeModule.Prepare(this);
	
				}
	
				this.lastImageLocalization = true;
				this.lastImageLocalizationKey = key;
				this.lastImageLocalizationParameters = parameters;
	
				this.SetImage(ResourceAuto.CreateResourceRequest(UnityEngine.UI.Windows.Plugins.Localization.LocalizationSystem.GetSpritePath(key, parameters)));
	
				//this.SetImage(UnityEngine.UI.Windows.Plugins.Localization.LocalizationSystem.GetSprite(key, parameters));
				//WindowSystemResources.Unload(this, this.GetResource());
				//WindowSystemResources.Load(this, onDataLoaded: null, onComplete: null, customResourcePath: UnityEngine.UI.Windows.Plugins.Localization.LocalizationSystem.GetSpritePath(key, parameters));
	
				return this;
	
			}
	
			public IImageComponent SetImage(Sprite sprite) {
	
				return this.SetImage(sprite, this.preserveAspect, false, null, false);
	
			}
	
			public IImageComponent SetImage(Sprite sprite, bool immediately) {
	
				return this.SetImage(sprite, this.preserveAspect, false, null, immediately);
	
			}
	
			public IImageComponent SetImage(Sprite sprite, System.Action onComplete) {
	
				return this.SetImage(sprite, this.preserveAspect, false, onComplete, false);
	
			}
	
			public IImageComponent SetImage(Sprite sprite, System.Action onComplete, bool immediately) {
	
				return this.SetImage(sprite, this.preserveAspect, false, onComplete, immediately);
	
			}
	
			public IImageComponent SetImage(Sprite sprite, bool preserveAspect, bool withPivotsAndSize, System.Action onComplete) {
	
				return this.SetImage(sprite, preserveAspect, withPivotsAndSize, onComplete, false);
	
			}
	
			public IImageComponent SetImage(Sprite sprite, bool preserveAspect, bool withPivotsAndSize, System.Action onComplete = null, bool immediately = false) {
				
				if (this.image != null) {
	
					if (this.imageCrossFadeModule.IsValid() == true) {
	
						this.imageCrossFadeModule.Prepare(this);
	
					}
	
					this.image.preserveAspect = preserveAspect;
	
					if (withPivotsAndSize == true && sprite != null) {
	
						var rect = (this.transform as RectTransform);
						rect.sizeDelta = sprite.rect.size;
						rect.pivot = sprite.GetPivot();
						rect.anchoredPosition = Vector2.zero;
	
					}
	
					if (immediately == false && this.imageCrossFadeModule.IsValid() == true) {
	
						this.imageCrossFadeModule.FadeTo(this, sprite, onComplete);
	
					} else {
	
						this.image.sprite = sprite;
	
						if (onComplete != null) onComplete.Invoke();
	
					}
	
				} else {
	
					if (onComplete != null) onComplete.Invoke();
	
				}
	
				return this;
	
			}
	
			public IImageComponent SetImage(Texture texture) {
	
				return this.SetImage(texture, this.preserveAspect, null, false);
	
			}
	
			public IImageComponent SetImage(Texture texture, bool immediately) {
	
				return this.SetImage(texture, this.preserveAspect, null, immediately);
	
			}
	
			public IImageComponent SetImage(Texture texture, System.Action onComplete) {
	
				return this.SetImage(texture, this.preserveAspect, onComplete, false);
	
			}
	
			public IImageComponent SetImage(Texture texture, System.Action onComplete, bool immediately) {
	
				return this.SetImage(texture, this.preserveAspect, onComplete, immediately);
	
			}
	
			public IImageComponent SetImage(Texture texture, bool preserveAspect, System.Action onComplete) {
	
				return this.SetImage(texture, preserveAspect, onComplete, false);
	
			}
	
			public IImageComponent SetImage(Texture texture, bool preserveAspect, System.Action onComplete, bool immediately) {
	
				//MovieSystem.UnregisterOnUpdateTexture(this.ValidateTexture);
				//MovieSystem.Stop(this, this.rawImage.texture.GetInstanceID());
	
				if (this.rawImage != null) {
	
					if (this.imageCrossFadeModule.IsValid() == true) {
	
						this.imageCrossFadeModule.Prepare(this);
	
					}
	
					if (immediately == false && this.imageCrossFadeModule.IsValid() == true) {
	
						this.imageCrossFadeModule.FadeTo(this, texture, onComplete);
						
					} else {
						
						this.rawImage.texture = texture;
	
						if (onComplete != null) onComplete.Invoke();
	
					}
	
				} else {
	
					if (onComplete != null) onComplete.Invoke();
	
				}
				
				return this;
	
			}
			
			public override Color GetColor() {
				
				Color color = Color.white;
				if (this.image != null) {
					
					color = this.image.color;
					
				} else if (this.rawImage != null) {
					
					color = this.rawImage.color;
					
				}
	
				return color;
	
			}
	
			public override void SetColor(Color color) {
	
				if (this.image != null) {
					
					this.image.color = color;
					
				}
	
				if (this.rawImage != null) {
					
					this.rawImage.color = color;
					
				}
	
			}
	
			public IAlphaComponent SetAlpha(float value) {
	
				var color = this.GetColor();
				color.a = value;
				this.SetColor(color);
				
				return this;
	
			}
	
			public IImageComponent SetMaterial(Material material, bool setMainTexture = false, System.Action onComplete = null) {
	
				MovieSystem.UnregisterOnUpdateMaterial(this.ValidateMaterial);
	
				if (material == null) {
	
					if (this.image != null) {
	
						this.image.material = null;
						this.image.SetMaterialDirty();
	
					} else if (this.rawImage != null) {
	
						this.rawImage.material = null;
						this.rawImage.SetMaterialDirty();
	
					}
	
	
					if (onComplete != null) onComplete.Invoke();
					return this;
	
				}
	
				MovieSystem.RegisterOnUpdateMaterial(this.ValidateMaterial);
	
				if (this.image != null) {
	
					if (this.image.enabled == false) this.image.enabled = true;
	
					var tex = material.mainTexture;
					if (this.imageCrossFadeModule.IsValid() == true) {
	
						this.imageCrossFadeModule.FadeTo<Image>(this, material, () => {
	
							if (setMainTexture == true) {
	
								var sprite = Sprite.Create(tex as Texture2D, new Rect(0f, 0f, tex.width, tex.height), Vector2.one * 0.5f);
								this.image.sprite = sprite;
	
							}
	
							this.image.SetMaterialDirty();
	
							if (onComplete != null) onComplete.Invoke();
	
						}, ImageCrossFadeModule.DataType.Material);
	
					} else {
	
						if (setMainTexture == true) {
	
							var sprite = Sprite.Create(tex as Texture2D, new Rect(0f, 0f, tex.width, tex.height), Vector2.one * 0.5f);
							this.image.sprite = sprite;
	
						}
	
						this.image.material = material;
						this.image.SetMaterialDirty();
	
						if (onComplete != null) onComplete.Invoke();
	
					}
	
				} else if (this.rawImage != null) {
	
					if (this.rawImage.enabled == false) this.rawImage.enabled = true;
	
					var tex = material.mainTexture;
					if (this.imageCrossFadeModule.IsValid() == true) {
	
						this.imageCrossFadeModule.FadeTo<RawImage>(this, material, () => {
	
							if (setMainTexture == true) {
	
								this.rawImage.texture = tex;
	
							}
							this.rawImage.SetMaterialDirty();
	
							if (onComplete != null) onComplete.Invoke();
	
						}, ImageCrossFadeModule.DataType.Material);
	
					} else {
	
						if (setMainTexture == true) {
						
							this.rawImage.texture = tex;
	
						}
	
						this.rawImage.material = material;
						this.rawImage.SetMaterialDirty();
	
						if (onComplete != null) onComplete.Invoke();
	
					}
	
				}
	
				return this;
	
			}
	
			public void ValidateMaterial(Material material) {
				
				if (this.rawImage != null) {
	
					this.rawImage.texture = this.rawImage.material.mainTexture;
					if (this.imageCrossFadeModule.IsValid() == true) {
	
						this.imageCrossFadeModule.ValidateMaterial(material);
	
					}
					//if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true) UnityEngine.Debug.Log("MATERIAL DIRTY: " + this.rawImage.texture, this);
	
				}
	
			}
			/*
			public void ModifyMesh(Mesh mesh) {}
	
			private System.Collections.Generic.List<UIVertex> modifyVertsTemp = new System.Collections.Generic.List<UIVertex>();
			public void ModifyMesh(VertexHelper helper) {
	
				if (this.rawImage != null && this.preserveAspect == true) {
	
					var vh = helper;
					var drawingDimensions = ME.Utilities.GetDrawingDimensions(this.rawImage, this.preserveAspect, this.rawImage.texture == null ? Vector2.zero : new Vector2(this.rawImage.texture.width, this.rawImage.texture.height), Vector4.zero);
					var vector = new Vector4(this.rawImage.uvRect.x, this.rawImage.uvRect.y, this.rawImage.uvRect.width, this.rawImage.uvRect.height);
					var color = this.GetColor();
					vh.Clear();
					vh.AddVert(new Vector3(drawingDimensions.x, drawingDimensions.y), color, new Vector2(vector.x, vector.y));
					vh.AddVert(new Vector3(drawingDimensions.x, drawingDimensions.w), color, new Vector2(vector.x, vector.w));
					vh.AddVert(new Vector3(drawingDimensions.z, drawingDimensions.w), color, new Vector2(vector.z, vector.w));
					vh.AddVert(new Vector3(drawingDimensions.z, drawingDimensions.y), color, new Vector2(vector.z, vector.y));
					vh.AddTriangle(0, 1, 2);
					vh.AddTriangle(2, 3, 0);
	
				}
	
				if (this.flipHorizontal == true ||
					this.flipVertical == true ||
					this.flipHorizontalInternal == true ||
					this.flipVerticalInternal == true) {
	
					this.modifyVertsTemp.Clear();
					helper.GetUIVertexStream(this.modifyVertsTemp);
	
					this.ModifyVertices(this.modifyVertsTemp);
	
					helper.AddUIVertexTriangleStream(this.modifyVertsTemp);
	
				}
	
			}
	
			public void ModifyVertices(System.Collections.Generic.List<UIVertex> verts) {
	
				var rt = this.GetRectTransform();
				var rectCenter = rt.rect.center;
				for (var i = 0; i < verts.Count; ++i) {
					
					var v = verts[i];
					v.position = new Vector3(
						((this.flipHorizontal == true || this.flipHorizontalInternal == true) ? (v.position.x + (rectCenter.x - v.position.x) * 2f) : v.position.x),
						((this.flipVertical == true || this.flipVerticalInternal == true) ? (v.position.y + (rectCenter.y - v.position.y) * 2f) : v.position.y),
						v.position.z
					);
					verts[i] = v;
	
				}
	
			}*/
	#endregion

		#region macros UI.Windows.TextComponent 
	/*
	 * This code is auto-generated by Macros Module
	 * Do not change anything
	 */
	[Header("Text Component")]
			[BeginGroup]
			[SerializeField]
			private MaskableGraphic text;
			[SerializeField]
			private TextValueFormat valueFormat;
			[SerializeField][BitMask(typeof(FullTextFormat))]
			private FullTextFormat fullTextFormat;
			[SerializeField][BitMask(typeof(RichTextFlags))]
			private RichTextFlags richTextFlags = RichTextFlags.Color | RichTextFlags.Bold | RichTextFlags.Italic | RichTextFlags.Size | RichTextFlags.Material | RichTextFlags.Quad;
	
			public UnityEngine.UI.Windows.Plugins.Localization.LocalizationKey textLocalizationKey;
			
			[SerializeField]
			private bool valueAnimate = false;
			[SerializeField][ReadOnly("valueAnimate", state: false)]
			private float valueAnimateDuration = 2f;
			[EndGroup][SerializeField]
			private TextCrossFadeModule textCrossFadeModule = new TextCrossFadeModule();
	
			private long valueAnimateLastValue;
			private long tempLastValue = long.MinValue;
			private TextValueFormat tempLastFormat = TextValueFormat.None;
	
			Graphic ITextComponent.GetGraphicSource() {
	
				return this.text;
	
			}
	
			public ITextComponent SetBestFit(bool state, int minSize = 10, int maxSize = 40) {
				
				if (this.text != null) {
					
					this.SetBestFitState(state);
					this.SetBestFitMinSize(minSize);
					this.SetBestFitMaxSize(maxSize);
					
				}
	
				return this;
	
			}
	
			public ITextComponent SetTextLocalizationKey(UnityEngine.UI.Windows.Plugins.Localization.LocalizationKey key) {
	
				this.textLocalizationKey = key;
	
				return this;
	
			}
	
			public ITextComponent SetBestFitState(bool state) {
	
				if (TextComponentUGUIAddon.IsValid(this.text) == true) TextComponentUGUIAddon.SetBestFitState(this.text, state);
				if (TextComponentTMPAddon.IsValid(this.text) == true) TextComponentTMPAddon.SetBestFitState(this.text, state);
	
				return this;
	
			}
			
			public ITextComponent SetBestFitMinSize(int size) {
	
				if (TextComponentUGUIAddon.IsValid(this.text) == true) TextComponentUGUIAddon.SetBestFitMinSize(this.text, size);
				if (TextComponentTMPAddon.IsValid(this.text) == true) TextComponentTMPAddon.SetBestFitMinSize(this.text, size);
	
				return this;
	
			}
			
			public ITextComponent SetBestFitMaxSize(int size) {
	
				if (TextComponentUGUIAddon.IsValid(this.text) == true) TextComponentUGUIAddon.SetBestFitMaxSize(this.text, size);
				if (TextComponentTMPAddon.IsValid(this.text) == true) TextComponentTMPAddon.SetBestFitMaxSize(this.text, size);
	
				return this;
	
			}
	
			public int GetFontSize() {
	
				if (TextComponentUGUIAddon.IsValid(this.text) == true) return TextComponentUGUIAddon.GetFontSize(this.text);
				if (TextComponentTMPAddon.IsValid(this.text) == true) return TextComponentTMPAddon.GetFontSize(this.text);
	
				return 0;
				
			}
	
			public ITextComponent SetFontSize(int fontSize) {
	
				if (TextComponentUGUIAddon.IsValid(this.text) == true) TextComponentUGUIAddon.SetFontSize(this.text, fontSize);
				if (TextComponentTMPAddon.IsValid(this.text) == true) TextComponentTMPAddon.SetFontSize(this.text, fontSize);
	
				return this;
	
			}
	
			public ITextComponent SetLineSpacing(float value) {
	
				if (TextComponentUGUIAddon.IsValid(this.text) == true) TextComponentUGUIAddon.SetLineSpacing(this.text, value);
				if (TextComponentTMPAddon.IsValid(this.text) == true) TextComponentTMPAddon.SetLineSpacing(this.text, value);
	
				return this;
	
			}
			
			public ITextComponent SetRichText(bool state) {
	
				if (TextComponentUGUIAddon.IsValid(this.text) == true) TextComponentUGUIAddon.SetRichText(this.text, state);
				if (TextComponentTMPAddon.IsValid(this.text) == true) TextComponentTMPAddon.SetRichText(this.text, state);
	
				return this;
	
			}
	
			public float GetContentHeight(float heightPadding = 0f) {
				
				if (this.text == null) return 0f;
				
				return this.GetContentHeight(this.GetText(), heightPadding);
				
			}
			
			public float GetContentHeight(string text, float heightPadding = 0f) {
				
				if (this.text == null) return 0f;
				
				return this.GetContentHeight(text, (this.transform.root as RectTransform).rect.size) + heightPadding;
				
			}
	
			public float GetContentHeight(string text, Vector2 containerSize) {
	
				if (this.text == null) return 0f;
	
				if (TextComponentUGUIAddon.IsValid(this.text) == true) return TextComponentUGUIAddon.GetContentHeight(this.text, text, containerSize);
				if (TextComponentTMPAddon.IsValid(this.text) == true) return TextComponentTMPAddon.GetContentHeight(this.text, text, containerSize);
	
				return 0f;
	
			}
	
			public ITextComponent SetTextAlignByGeometry(bool state) {
	
				if (TextComponentUGUIAddon.IsValid(this.text) == true) TextComponentUGUIAddon.SetTextAlignByGeometry(this.text, state);
				if (TextComponentTMPAddon.IsValid(this.text) == true) TextComponentTMPAddon.SetTextAlignByGeometry(this.text, state);
	
				return this;
	
			}
	
			public ITextComponent SetTextVerticalOverflow(VerticalWrapMode mode) {
	
				if (TextComponentUGUIAddon.IsValid(this.text) == true) TextComponentUGUIAddon.SetTextVerticalOverflow(this.text, mode);
				if (TextComponentTMPAddon.IsValid(this.text) == true) TextComponentTMPAddon.SetTextVerticalOverflow(this.text, mode);
	
				return this;
	
			}
	
			public ITextComponent SetTextHorizontalOverflow(HorizontalWrapMode mode) {
	
				if (TextComponentUGUIAddon.IsValid(this.text) == true) TextComponentUGUIAddon.SetTextHorizontalOverflow(this.text, mode);
				if (TextComponentTMPAddon.IsValid(this.text) == true) TextComponentTMPAddon.SetTextHorizontalOverflow(this.text, mode);
	
				return this;
	
			}
	
			public ITextComponent SetTextAlignment(TextAnchor anchor) {
	
				if (TextComponentUGUIAddon.IsValid(this.text) == true) TextComponentUGUIAddon.SetTextAlignment(this.text, anchor);
				if (TextComponentTMPAddon.IsValid(this.text) == true) TextComponentTMPAddon.SetTextAlignment(this.text, anchor);
	
				return this;
	
			}
	
			public string GetText() {
	
				if (TextComponentUGUIAddon.IsValid(this.text) == true) return TextComponentUGUIAddon.GetText(this.text);
				if (TextComponentTMPAddon.IsValid(this.text) == true) return TextComponentTMPAddon.GetText(this.text);
	
				return string.Empty;
	
			}
	
			public ITextComponent SetValueAnimate(bool state) {
				
				this.valueAnimate = state;
				
				return this;
				
			}
			
			public ITextComponent SetValueAnimateDuration(float duration) {
				
				this.valueAnimateDuration = duration;
				
				return this;
				
			}
	
			public ITextComponent SetFullTextFormat(FullTextFormat format) {
				
				this.fullTextFormat = format;
				
				return this;
				
			}
	
			public ITextComponent SetValueFormat(TextValueFormat format) {
	
				this.valueFormat = format;
	
				return this;
	
			}
			
			public ITextComponent SetValue(int value) {
				
				this.SetValue(value, this.valueFormat);
				
				return this;
				
			}
			
			public ITextComponent SetValue(int value, TextValueFormat format) {
				
				return this.SetValue(value, format, this.valueAnimate);
				
			}
			
			public ITextComponent SetValue(int value, TextValueFormat format, bool animate) {
				
				return this.SetValue((long)value, format, animate);
				
			}
	
			public ITextComponent SetValue(long value) {
				
				this.SetValue(value, this.valueFormat);
	
				return this;
	
			}
	
			public ITextComponent SetValue(long value, TextValueFormat format) {
	
				return this.SetValue(value, format, this.valueAnimate);
	
			}
	
			public ITextComponent SetValue(long value, TextValueFormat format, bool animate) {
	
				return this.SetValue_INTERNAL(value, format, animate, fromTweener: false);
	
			}
	
			private ITextComponent SetValue_INTERNAL(long value, TextValueFormat format, bool animate, bool fromTweener) {
	
				if (fromTweener == true && this.tempLastValue == value && this.tempLastFormat == format) return this;
				this.tempLastValue = value;
				this.tempLastFormat = format;
	
				var tag = this.GetCustomTag(this.text);
				if (fromTweener == false && TweenerGlobal.instance != null) TweenerGlobal.instance.removeTweens(tag);
	
				if (animate == true && TweenerGlobal.instance != null) {
	
					this.tempLastValue = value - 1L;
	
					var duration = this.valueAnimateDuration;
					if (Mathf.Abs(this.valueAnimateLastValue - value) < 2) duration = 0.2f;
					TweenerGlobal.instance.addTweenCount(this, duration, this.valueAnimateLastValue, value, format, (v) => { this.SetValue_INTERNAL(v, format, animate: false, fromTweener: true); }).tag(tag);
					
				} else {
					
					this.valueAnimateLastValue = value; 
					this.SetText_INTERNAL(TextComponent.FormatValue(value, format));
					
				}
				
				return this;
	
			}
	
			public ITextComponent SetHyphenSymbol() {
	
				return this.SetText("\u2014");
	
			}
	
			private bool lastTextLocalization = false;
			private Plugins.Localization.LocalizationKey lastTextLocalizationKey;
			private object[] lastTextLocalizationParameters;
			public ITextComponent SetText(Plugins.Localization.LocalizationKey key, params object[] parameters) {
	
				this.lastTextLocalization = true;
				this.lastTextLocalizationKey = key;
				this.lastTextLocalizationParameters = parameters;
	
				return this.SetText(Plugins.Localization.LocalizationSystem.Get(key, parameters));
	
			}
	
			public ITextComponent SetText(string text) {
				
				if (TweenerGlobal.instance != null) TweenerGlobal.instance.removeTweens(this);
	
				this.SetText_INTERNAL(text);
	
				return this;
	
			}
	
			private void SetText_INTERNAL(string text) {
	
				if (text == null) text = string.Empty;
	
				if (this.text != null) {
	
					System.Action onComplete = () => {
	
						bool supportRichText = false;
						if (TextComponentUGUIAddon.IsValid(this.text) == true) supportRichText = TextComponentUGUIAddon.IsRichtextSupported(this.text);
						if (TextComponentTMPAddon.IsValid(this.text) == true) supportRichText = TextComponentTMPAddon.IsRichtextSupported(this.text);
	
						if (supportRichText == true) {
	
							text = TextComponent.ParseRichText(text, this.GetFontSize(), this.richTextFlags);
	
						}
	
						text = TextComponent.FullTextFormat(text, this.fullTextFormat);
	
						if (TextComponentUGUIAddon.IsValid(this.text) == true) TextComponentUGUIAddon.SetText(this.text, text);
						if (TextComponentTMPAddon.IsValid(this.text) == true) TextComponentTMPAddon.SetText(this.text, text);
	
					};
	
					if (this.textCrossFadeModule.IsValid() == true && TextComponentUGUIAddon.IsValid(this.text) == true) {
	
						this.textCrossFadeModule.Prepare(this);
						this.textCrossFadeModule.FadeTo(this, text, onComplete);
	
					} else {
	
						onComplete.Invoke();
	
					}
	
				}
	
			}
	
			public virtual ITextComponent SetTextAlpha(float value) {
	
				var color = this.GetTextColor();
				color.a = value;
				this.SetTextColor(color);
	
				return this;
	
			}
	
			public virtual ITextComponent SetTextColor(Color color) {
				
				if (this.text != null) this.text.color = color;
	
				return this;
	
			}
			
			public virtual Color GetTextColor() {
	
				if (this.text == null) return Color.white;
	
				return this.text.color;
				
			}
	#endregion

		#if UNITY_EDITOR
		public override void OnValidateEditor() {

			base.OnValidateEditor();

			if (this.button == null) {

				var buttons = this.GetComponentsInChildren<Button>(true);
				if (buttons.Length == 1) this.button = buttons[0];

			}

			#region macros UI.Windows.Editor.TextComponent 
	/*
	 * This code is auto-generated by Macros Module
	 * Do not change anything
	 */
	if (this.text == null) this.text = ME.Utilities.FindReferenceChildren<Text>(this);
	#endregion

			#region macros UI.Windows.Editor.ImageComponent 
	/*
	 * This code is auto-generated by Macros Module
	 * Do not change anything
	 */
	{
					
					//if (this.image == null) this.image = this.GetComponent<Image>();
					//if (this.rawImage == null) this.rawImage = this.GetComponent<RawImage>();
	
					WindowSystemResources.Validate(this);
	
					this.imageCrossFadeModule.Init(this);
					this.imageCrossFadeModule.OnValidateEditor();
	
					/*if (this.image == null || this.image.GetComponent<UIFlippable>() == null ||
						this.rawImage == null || this.rawImage.GetComponent<UIFlippable>() == null) {
	
						if (this.flippableEffect != null) ME.EditorUtilities.Destroy(this.flippableEffect, () => { this.flippableEffect = null; });
	
					}
	
					if (this.rawImage == null || this.rawImage.GetComponent<UIPreserveAspect>() == null) {
	
						if (this.preserveAspectEffect != null) ME.EditorUtilities.Destroy(this.preserveAspectEffect, () => { this.preserveAspectEffect = null; });
	
					}*/
	
					var gr = (this.rawImage as Graphic ?? this.image as Graphic);
					if (gr != null) {
	
						this.flippableEffect = gr.GetComponent<UIFlippable>();
						if (this.flippableEffect == null) this.flippableEffect = gr.gameObject.AddComponent<UIFlippable>();
						if (this.flippableEffect != null) {
	
							this.flippableEffect.horizontal = this.flipHorizontal;
							this.flippableEffect.vertical = this.flipVertical;
	
						}
	
					}
	
					if (this.rawImage != null) {
	
						this.preserveAspectEffect = this.rawImage.GetComponent<UIPreserveAspect>();
						if (this.preserveAspectEffect == null) this.preserveAspectEffect = this.rawImage.gameObject.AddComponent<UIPreserveAspect>();
						if (this.preserveAspectEffect != null) {
	
							this.preserveAspectEffect.preserveAspect = this.preserveAspect;
							this.preserveAspectEffect.rawImage = this.rawImage;
	
						}
	
					}
	
				}
	#endregion

		}
		#endif

	}

}
